package org.droid.campus.util;

import org.droid.campus.common.Enums;

public class RespStatusBuilder {
	public static StringBuffer message(int code, String msg) {
		return new StringBuffer()
				.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>")
				.append("<resp>")
				.append("<head>")
				.append("<status>").append(code).append("</status>")
				.append("<desc><![CDATA[").append(msg).append("]]></desc>")
				.append("</head>")
				.append("</resp>");
	}
	
	public static StringBuffer message(int code , String msg , String data){
		return new StringBuffer()
		.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>")
		.append("<resp>")
		.append("<head>")
		.append("<status>").append(code).append("</status>")
		.append("<desc><![CDATA[").append(msg).append("]]></desc>")
		.append("</head>")
		.append("<data>")
		.append(data)
		.append("</data>")
		.append("</resp>");
	}
	
	public static StringBuffer message(int code , String msg , StringBuffer data){
		return message(code , msg , data.toString()) ;
	}
	
	public static StringBuffer message(int code , String msg , int pageCount , int pageIndex, String data){
		return new StringBuffer()
		.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>")
		.append("<resp>")
		.append("<head>")
		.append("<status>").append(code).append("</status>")
		.append("<desc><![CDATA[").append(msg).append("]]></desc>")
		.append("<page>")
		.append(pageIndex)
		.append("</page>")
		.append("<total>")
		.append(pageCount)
		.append("</total>")
		.append("</head>")
		.append("<data>")
		.append(data)
		.append("</data>")
		.append("</resp>");
	}
	
	public static StringBuffer message(int code , String msg , int pageCount , int pageIndex, StringBuffer data){
		return message(code , msg , pageCount , pageIndex , data.toString()) ;
	}
	
	public static StringBuffer message(Enums.ActionStatus status) {
		return new StringBuffer()
				.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>")
				.append("<resp>")
				.append("<head>")
				.append("<status>").append(status.inValue()).append("</status>")
				.append("<desc><![CDATA[").append(status.getDescription()).append("]]></desc>")
				.append("</head>")
				.append("</resp>");
	}
}
